package palmtop.com.palmtop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;

import java.lang.reflect.Type;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import palmtop.com.palmtop.R;
import palmtop.com.palmtop.adapter.ClueAdapter;
import palmtop.com.palmtop.adapter.PopulationAdapter;
import palmtop.com.palmtop.adapter.ProcesstaskAdapter;
import palmtop.com.palmtop.model.Clue;
import palmtop.com.palmtop.model.Processtask;
import palmtop.com.palmtop.model.Reportpopulation;
import palmtop.com.palmtop.util.Config;
import palmtop.com.palmtop.util.NetUtil;

public class ClueActivity extends BaseActivity {

    @BindView(R.id.mtitle)
    TextView mtitle;
    @BindView(R.id.clueList)
    ListView clueList;
    private ArrayList<Clue> arrlist;
    private ClueAdapter adapter;
    Clue clue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clue, Config.toptitle, 1);
        MyApplication app = (MyApplication) getApplication();
        app.addActivityList(ClueActivity.this);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        arrlist = new ArrayList<Clue>();
        mtitle.setText("线索搜集");
        clue = (Clue)getIntent().getSerializableExtra("clue");
        if(clue!=null){
            RequestParams params = new RequestParams(Config.SERVER_URL + "clue/getByUnitid");
            params.addBodyParameter("unitid",String.valueOf(clue.getUnitid()));
            NetUtil.postData(params, new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    Gson gson = new Gson();
                    Type listType = new TypeToken<ArrayList<Clue>>() {
                    }.getType();
                    final ArrayList<Clue> list = gson.fromJson(result,listType);
                    adapter = new ClueAdapter(list,ClueActivity.this);
                    clueList.setAdapter(adapter);

                    /*clueList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            Intent intent = new Intent();
                            intent.putExtra("clue",list.get(i));
                            intent.setClass(ClueActivity.this,CluedetailActivity.class);
                            startActivity(intent);
                        }
                    });*/
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {}
                @Override
                public void onCancelled(CancelledException cex) {}
                @Override
                public void onFinished() {}
            });
        }
    }
}
